<template>
	<!-- 我的/我的找活详情页 -->
  <view>
    <myitem v-if="list.length" :list="list" />
    <u-empty class="empty" v-else text="暂无数据" mode="list"></u-empty>
    <u-loadmore
      v-if="list.length != 0"
      :status="status"
      @loadmore="loadmore"
    ></u-loadmore>
  </view>
</template>

<script>
import myitem from "./list.vue";
import api from "../../../../api/routes.js";
export default {
  components: {
    myitem,
  },
  data() {
    return {
      page: 1,
      limit: 5,
      status: "loadmore",
      list: [],

      // 拿到的数据总条数
      total: 0,
      //判断是否发送请求的条件
      load: false,
    };
  },
  onLoad() {
    this.getList();
  },
  onReachBottom() {
    if (this.status === "loadmore") {
      this.loadmore();
    }
  },
  methods: {
    async getList() {
      // 判断当前是否在请求，如果为true正在请求数据，就让他返回空，如果为false没在请求，就让它开始请求数据
      if (this.load) {
        return;
      }
      this.load = true;
      // 请求数据时，状态改为加载中状态
      this.status = "loading";
      const res = await this.$myRequest({
        url: api.pageMyApplyJob,
        method: "POST",
        data: {
          page: this.page,
          limit: this.limit,
        },
      });
      this.load = false;
      if (res.data.code !== 0) {
        return uni.showToast({
          title: res.msg,
          icon: "none",
        });
        this.status = "nomore";
      }
      this.total = res.data.page.totalCount;
      this.list = [...this.list, ...res.data.page.list];

      this.ismore();
    },

    ismore() {
      if (this.total === this.list.length) {
        this.status = "nomore";
      } else {
        this.status = "loadmore";
      }
    },
    loadmore() {
      this.page++;
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
.empty{
  display: block;
  margin: 120px 0 0;
}
</style>


